package com.example.chatroom.common.config;

import com.example.chatroom.common.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
public class AppConfigurer implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 第一个/前面就是URL的地址 127.0.0.1、。。。。
     */

    private static final List<String> excludes= Arrays.asList(
            "/**/*.html",
            "/css/**",
            "/js/**",
            "/img/**",
            "/*.jpg",
            "/*.png",
            "/*.webp",
            "/favicon.ico",
            "/user/login",
            "/user/register"
    );
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludes);
    }
}